package com.situ.springbootscientific.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.springbootscientific.mapper.ResearchersMapper;
import com.situ.springbootscientific.pojo.Auth;
import com.situ.springbootscientific.pojo.Researchers;
import com.situ.springbootscientific.pojo.query.ResearchersQuery;
import com.situ.springbootscientific.pojo.vo.ResearchIdVo;
import com.situ.springbootscientific.pojo.vo.ResearchersVo;
import com.situ.springbootscientific.service.IResearchersService;
import com.situ.springbootscientific.utils.PageRusults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResearchersServiceImpl implements IResearchersService {
    @Autowired
    private ResearchersMapper researchersMapper;
    @Override
    public Researchers login(String name, String password) {
        Researchers researchers = researchersMapper.login(name,password);
        return researchers;
    }

    @Override
    public PageRusults list(ResearchersQuery researchersQuery) {
        PageHelper.startPage(researchersQuery.getPage(), researchersQuery.getLimit());
        //1.查询当前页列表
        List<ResearchersVo> researchersVoList = researchersMapper.list(researchersQuery);
        //2.用一个小插件查询总数量
        PageInfo pageInfo = new PageInfo(researchersVoList);
        int total = (int) pageInfo.getTotal();
        return new PageRusults(0,"",total,researchersVoList);
    }

    @Override
    public List<ResearchIdVo> selectById(Integer id) {
        List<ResearchIdVo> researchIdVo = researchersMapper.selectById(id);
        return researchIdVo;
    }

    @Override
    public void avatar(Researchers researchers) {
        researchersMapper.avatar(researchers);
    }


}
